package ace.module.oauth2.server.sdk.core.api.impl;

import ace.cmp.core.model.R;
import ace.module.oauth2.server.api.Oauth2Api;
import ace.module.oauth2.server.api.model.dto.ext.Oauth2AccessTokenDto;
import ace.module.oauth2.server.api.model.input.Oauth2GetTokenByExternalUserInput;
import ace.module.oauth2.server.sdk.core.service.Oauth2AuthApiService;
import jakarta.annotation.Nullable;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * @author caspar
 * @date 2023/10/12 11:06
 */
@AllArgsConstructor
@Component
public class Oauth2ApiImpl implements Oauth2Api {

  private final Oauth2AuthApiService oauth2AuthApiService;

  @Override
  public R<Oauth2AccessTokenDto> getTokenByExternalUserGrantType(Oauth2GetTokenByExternalUserInput input) {
    return oauth2AuthApiService.getTokenByExternalUserGrantType(input);
  }

  @Override
  public R<Oauth2AccessTokenDto> getTokenByRestGrantTypeAndPasswordMethod(
      String authorization,
      String username,
      String password,
      @Nullable Long captchaItemId,
      @Nullable String code
  ) {
    return oauth2AuthApiService.getTokenByRestGrantTypeAndPasswordMethod(authorization, username, password, captchaItemId, code);
  }
}
